﻿Imports System.Data
Imports System.Data.SqlClient
Public Class CondicionVentaDatos

    'Obtiene todas las condiciones de venta
    Function obtenerCondicionVenta() As DataSet
        Dim conex As New Conexion
        Dim coneccion As New SqlConnection
        Dim dt As New DataTable
        Dim ds As New DataSet
        Try
            coneccion = conex.conectar()
            coneccion.Open()

            Dim query As String = "SELECT CNV_Codigo, CNV_Descripcion " &
                                  "FROM CondicionVenta " &
                                  "WHERE CNV_Activo = '1'"

            Dim comando As New SqlCommand(query, coneccion)
            Dim adapter As New SqlDataAdapter(comando)
            adapter.Fill(ds)

            dt = ds.Tables(0)
            Dim row As DataRow = dt.NewRow()
            row.Item("CNV_Codigo") = 0
            row.Item("CNV_Descripcion") = "Seleccionar..."
            dt.Rows.InsertAt(row, 0)
        Catch ex As SqlException
            MsgBox("La conexión no está disponible.")
        Catch e As Exception
            MsgBox(e.Message)
        Finally
            coneccion.Close()
        End Try

        Return ds
    End Function

End Class
